package mx.com.sinformex.simbel.db.eos;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;

/**
 * @author Oscar Ivan Hernandez Ventura [ oscar at sinformex dot com dot mx]
 *
 * @version $ Id : ReportParam.java , v 1.0 11/05/2009 angellore $
 * 
 */
@Entity(name="report_param")
public class ReportParam {

	private Integer reportParamId;
	private Integer reportId;
	private String name;
	private String description;
	private String field;
	private String dataType;
	private boolean required;
	private boolean staticParam;
	private String defaultValue;
	private boolean newItem = false;
	private Object valueData ;
	
	@Id
	@Column(name="report_param_id")
	@GeneratedValue(strategy=GenerationType.AUTO)	
	@NonVisual	
	public Integer getReportParamId() {
		return reportParamId;
	}
	public void setReportParamId(Integer reportParamId) {
		this.reportParamId = reportParamId;
	}
	
	@Column(name="report_id", nullable=false)
	@NonVisual
	public Integer getReportId() {
		return reportId;
	}
	public void setReportId(Integer reportId) {
		this.reportId = reportId;
	}
	
	@Column(nullable=true)
    @Validate("required")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(nullable=true)
    @Validate("required")
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column(nullable=true)
    @Validate("required")
	public String getField() {
		return field;
	}
	public void setField(String field) {
		this.field = field;
	}
	
	@Column(name="data_type",nullable=true)
    @Validate("required")
	public String getDataType() {
		return dataType;
	}
	public void setDataType(String dataType) {
		this.dataType = dataType;
	}
	
	@Column(name="required",nullable=false)
	@Validate("required")
	public boolean isRequired() {
		return required;
	}
	public void setRequired(boolean required) {
		this.required = required;
	}
	
	@Column(name="static",nullable=false)
	@Validate("required")
	public boolean isStaticParam() {
		return staticParam;
	}
	public void setStaticParam(boolean staticParam) {
		this.staticParam = staticParam;
	}
	
	@Column(name="default_value",nullable=false)
	@Validate("required")
	public String getDefaultValue() {
		return defaultValue;
	}
	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}
	@Transient
	public boolean isNewItem() {
		return newItem;
	}
	public void setNewItem(boolean newItem) {
		this.newItem = newItem;
	}
	@Transient
	public Object getValueData() {
		return valueData;
	}
	public void setValueData(Object valueData) {
		this.valueData = valueData;
	}

	public final String toString() {
		return String.format("[Id : %d ; Report : %d ]", getReportParamId(), getReportId());
	}

	public boolean equals (Object obj) {
		if (null == obj) return false;
		if (!(obj instanceof ReportParam)) return false;
		else {
			ReportParam param = (ReportParam) obj;
			if (null == this.getReportParamId() || null == param.getReportParamId()) return false;
			else return (this.getReportParamId().equals(param.getReportParamId()));
		}
	}
	
}
